<template>
  <div class="menu">
    <el-aside :width="isCollapse ? '65px' : '200px'">
      <el-menu router :default-active="activePath" class="el-menu-vertical-demo" @open="handleOpen" @close="handleClose"
        :collapse="isCollapse">
        <template v-for="(item, index) in menus">
          <el-submenu :index="item.path" :key="index" v-if="!item.hidden && item.meta.isXia == 1">
            <template slot="title">
              <i :class="item.iconClass"></i>
              <span slot="title">{{ item.name }}</span>
            </template>
            <el-menu-item-group v-for="(child, index) in item.children" :key="index">
              <el-menu-item :index="`${item.path}/${child.path}`">
                <i :class="child.iconClass"></i>
                {{ child.name }}
              </el-menu-item>
            </el-menu-item-group>
          </el-submenu>
          <el-menu-item :index="item.path" v-if="item.meta.isXia == 0 &&!item.hidden">
            <i :class="item.iconClass"></i>
            <span slot="title">{{ item.name }}</span>
          </el-menu-item>
        </template>
      </el-menu>
    </el-aside>
  </div>
</template>

<script>
export default {
  data() {
    return {
      isCollapse: false,
      menus: [],
      activePath: ""
    };
  },
  created() {
    // this.$router.options.routes.push( )
    this.menus = [...this.$router.options.routes];

    this.activePath = this.menus.find((i) => i.hidden != true).path;
  },
  methods: {
    handleOpen(key, keyPath) {
      console.log(key);
      console.log(key, keyPath);
    },
    handleClose(key, keyPath) {
      console.log(key, keyPath);
    }
  }
};
</script>

<style>
.menu .el-aside {
  background-color: #d3dce6;
  color: #333;
  text-align: center;
  line-height: 200px;
  overflow: hidden;
}

.menu .el-aside .el-menu {
  height: 100%;
  background-color: #fff;
}

.menu .el-aside .el-menu .el-submenu {
  text-align: left;
}
.menu .el-aside .el-menu .el-menu-item{
  text-align: left;
}
</style>
